﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DPS.Model
{
    class LabelStateModel
    {

        /// <summary>
        /// 状态类型
        /// </summary>
        public enum StateType {
            /// <summary>
            /// 未初始,接入电源后(Z命令送信前)
            /// </summary>
            UNINITIALIZED = 0x30,
            /// <summary>
            /// 待机
            /// </summary>
            STANDBY = 0x31,
            /// <summary>
            /// 作业中,没按哪个按钮
            /// </summary>
            WORKING = 0x32,
            /// <summary>
            /// 作业中Fn,Fn键按下
            /// </summary>
            WORKING_FN = 0x33,
            /// <summary>
            /// 作业结束
            /// </summary>
            WORK_FINISH = 0x34,
            /// <summary>
            /// 取消结束
            /// </summary>
            CANCEL_WORK = 0x35,
            /// <summary>
            /// 维护中
            /// </summary>
            TEST = 0x36,
            /// <summary>
            /// 电子标签异常
            /// </summary>
            EXCEPTION = 0x3F,
            /// <summary>
            /// 通讯超时
            /// </summary>
            TIME_OUT = 0xFF
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="iAddress">地址</param>
        /// <param name="iState">状态</param>
        /// <param name="iKey1">开关输入状态1</param>
        /// <param name="iKey2">开关输入状态2</param>
        public LabelStateModel(string iAddress, StateType iState, byte iKey1, byte iKey2) {
            Address = iAddress;
            State = iState;
            KeyIncrease = (iKey1 & (0x01 << 1)) > 0;
            KeyDecrease = (iKey1 & (0x01 << 2)) > 0;
            KeyConfirm = (iKey2 & (0x01 << 1)) > 0;
            KeyFn = (iKey2 & (0x01 << 2)) > 0;
        }

        /// <summary>
        /// 地址
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// 标签状态
        /// </summary>
        public StateType State { get; set; }
        /// <summary>
        /// 按键+状态
        /// </summary>
        public bool KeyIncrease { get; set; }
        /// <summary>
        /// 按键-状态
        /// </summary>
        public bool KeyDecrease { get; set; }
        /// <summary>
        /// 按键Fn状态
        /// </summary>
        public bool KeyFn { get; set; }
        /// <summary>
        /// 按键Confirm状态
        /// </summary>
        public bool KeyConfirm { get; set; }
    }
}
